﻿using System.Linq;

namespace nRoute.Components.Composition.Adapters
{
    public class QueryableLocatorAdapter<T> 
        : LocatorAdapterBase<T, IQueryable<T>>
        where 
            T : class
    {
        public QueryableLocatorAdapter()
            : base((b, s) =>
            {
                // note_ we are ignoring the string "s" type sent in
                if (b.ResourceCatalog.IsResourceable<T>())
                {
                    var _catalog = ((IResourceCatalogEx)b.ResourceCatalog).GetResourceCatalog<T>();
                    return _catalog.AsQueryable().Select((l) => (T)l.GetResource(b));
                }
                else
                {
                    return Enumerable.Empty<T>().AsQueryable();
                }
            }) { }
    }
}